var  client = require('../database');
function  Note(note) {
    this.name =note.name;
    this.content =note.content;
}
var tableName = "note";
mysql = client.getDbCon();
module.exports = Note;

/** add note */
Note.prototype.save = function save(callback) {
    var  note = {
        name: this.name,
        content: this.content,
    };
    var sql = "insert into note (name,content,createTime) values(?,?,now())";
    mysql.query(sql,[note.name,note.content],function(err,results,fields){
        if (err) {
            throw err;
        } else {
            return callback(err, results[0], fields);
        }
    });
};

/** get note*/
Note.get = function get(page,size,callback){
    var sql = "select * from note order by createTime desc limit ?,?";
    mysql.query(sql,[page,size],function(err,results,fields){
        if (err) {
            throw err;
        } else {
            return callback(err, results, fields);
        }
    });
}

